#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll T,n,a[200005],pre[200005],lst[1000005],dp[200005],ans;
void solve(){
    scanf("%lld",&n),ans=0;
    for(int i=0;i<=1000000;i++)lst[i]=-1e10;
    for(int i=1;i<=n;i++)scanf("%lld",a+i),pre[i]=pre[i-1]+(a[i]==a[i-1]?a[i]:0LL);
    lst[0]=0;
    for(int i=2;i<=n;i++){
        dp[i]=max(lst[0]+pre[i-1],lst[a[i]]+pre[i-1]+a[i]);
        lst[0]=max(lst[0],-pre[i]+dp[i]);
        lst[a[i-1]]=max(lst[a[i]],-pre[i]+dp[i]);
        ans=max(ans,dp[i]+pre[n]-pre[i]);
    }
    printf("%lld\n",ans);
}
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    scanf("%lld",&T);
    while(T--)solve();
    return 0;
}
